home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Libraries & Documentation / Tutorial ƒ / Assignment5.p < prev    next >
Text File  |  1995-01-16  |  2KB  |  79 lines

  1. program Assignment5;
  2.     uses
  3. {$ifc UNDEFINED THINK_PASCAL}
  4.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, OSEvents, {}
  5. {$endc}
  6.         SAT;
  7.  
  8.     const
  9.         kSpeed = 5;
  10.     var
  11.         ignore: SpritePtr;
  12.         direction: Integer;
  13.         theSound: Handle;
  14.  
  15.     procedure HandleSprite (me: SpritePtr);
  16.     begin
  17.         GetMouse(me^.position);
  18.     end; {HandleSprite}
  19.  
  20.     procedure SetupSprite (me: SpritePtr);
  21.     begin
  22.         me^.task := @HandleSprite;
  23.         me^.face := SATGetFace(128);
  24.         SetRect(me^.hotRect, 0, 0, 32, 32);
  25.     end; {SetupSprite}
  26.  
  27.     procedure SetupTarget (me: SpritePtr);
  28.     forward;
  29.  
  30.     procedure HandleTarget (me: SpritePtr);
  31.     begin
  32.         me^.position.h := me^.position.h + direction;
  33.         if me^.position.h <= 0 then
  34.             direction := kSpeed;
  35.         if me^.position.h >= 200 then
  36.             direction := -kSpeed;
  37.  
  38.         if me^.kind <> -1 then {Hit me!}
  39.             begin
  40.                 me^.task := nil;
  41.                 ignore := SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), @SetupTarget);
  42. {We could also re-use the old sprite for a new one, if we like.}
  43.                 SATSoundPlay(theSound, 1, true);
  44.             end;
  45.     end; {HandleTarget}
  46.  
  47.     procedure SetupTarget (me: SpritePtr);
  48.     begin
  49.         me^.task := @HandleTarget;
  50.         me^.face := SATGetFace(129);
  51.         SetRect(me^.hotRect, 0, 0, 32, 32);
  52.         direction := kSpeed;
  53.     end; {SetupTarget}
  54.  
  55.     const
  56.         kTicksPerFrame = 2;
  57.     var
  58.         t: Longint;
  59.  
  60. begin
  61. {$ifc UNDEFINED THINK_PASCAL}
  62.     SATInitToolbox;
  63. {$endc}
  64.  
  65.     SATInit(128, 129, 478, 302);
  66.     ignore := SATNewSprite(1, 200, 200, @SetupSprite);
  67.     ignore := SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), @SetupTarget);
  68.     theSound := SATGetNamedSound('TestSound');
  69.     HideCursor;
  70.     while not Button do
  71.         begin
  72.             t := TickCount;
  73.             SATRun(true);
  74.             while TickCount < t + kTicksPerFrame do
  75.                 ;
  76.         end;
  77.     ShowCursor;
  78.     SATSoundShutup;
  79. end.